package com.airsystem.pos.bengkel.model;

import java.awt.GridBagLayout;
import java.math.BigDecimal;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;

import com.airsystem.pos.bengkel.component.DesktopFrame;
import com.airsystem.pos.bengkel.entity.DetailKendaraan;
import com.airsystem.pos.bengkel.entity.DetailLayanan;
import com.airsystem.pos.bengkel.entity.Kendaraan;
import com.airsystem.pos.bengkel.entity.Layanan;

/**
 * @author Fanny Irawan Sutawanir (fannyirawans@gmail.com)
 */
public class MasterServicesModel extends DesktopFrame {
	protected GridBagLayout baseLayout = new GridBagLayout();
	protected GridBagLayout panelLayout = new GridBagLayout();

	protected JPanel basePanel = new JPanel();
	protected JPanel buttonPanel = new JPanel();

	protected JLabel namaLabel = new JLabel();
	protected JLabel hargaLabel = new JLabel();
	protected JLabel merkLabel = new JLabel();
	protected JLabel submerkLabel = new JLabel();

	protected JTextField namaField = new JTextField();
	protected JTextField hargaField = new JTextField();
	protected JTextField merkField = new JTextField();
	protected JTextField submerkField = new JTextField();
	protected JTextField idField = new JTextField();

	protected JButton serviceButton = new JButton();
	protected JButton searchButton = new JButton();
	protected JButton vehicleButton = new JButton();
	protected JButton saveButton = new JButton();
	protected JButton updateButton = new JButton();
	protected JButton deleteButton = new JButton();
	protected JButton cancelButton = new JButton();

	protected Long targetedSvcType;

	protected DetailLayanan layananDetail;

	public MasterServicesModel() {
		super();
	}

	protected JTextComponent[] getComponent() {
		return new JTextComponent[] { namaField, hargaField, merkField, submerkField };
	}

	protected DetailLayanan getComponentData() {
		DetailLayanan detailLayanan = new DetailLayanan();

		Layanan layanan = new Layanan();
		layanan.setNama(namaField.getText().trim());

		if (!idField.getText().trim().isEmpty()) {
			detailLayanan.setId(Long.parseLong(idField.getText().trim()));
			layanan.setId(Long.parseLong(idField.getText().trim()));
		}

		Kendaraan kendaraan = new Kendaraan();
		kendaraan.setMerk(merkField.getText().trim());

		DetailKendaraan dtKendaraan = new DetailKendaraan();
		dtKendaraan.setSub_merk(submerkField.getText());
		dtKendaraan.setKendaraan(kendaraan);

		detailLayanan.setHarga(new BigDecimal(hargaField.getText()));
		detailLayanan.setDetail_kendaraan(dtKendaraan);
		detailLayanan.setLayanan(layanan);

		return detailLayanan;
	}
}